#include <iostream>
#include <opencv2/opencv.hpp>
#include "yolo_v2_class.hpp"

using namespace std;

int main()
{
    cout << "Hello World!" << endl;
        std::string cfg_file="yolov3-tiny.cfg";
        std::string weights_file = "yolov3-tiny_20000.weights";
        Detector *pDetector1 = new Detector(cfg_file,weights_file);

    std::string pattern = "./images/*.jpg";
    std::vector<cv::String> files;
    cv::glob(pattern,files,false);

    for(int j=0;j<files.size();j++){
        cv::Mat frame1 = cv::imread(files[j]);

        std::vector<bbox_t> result =  pDetector1->detect(frame1,0.5);
        for(int i=0;i<result.size();i++){
            bbox_t box = result[i];
            int w = box.w;
            int obj_id = box.obj_id;

            std::cout <<"result " <<std::endl;
            cv::Scalar color;
            switch(obj_id){
            case 0:
                color = cv::Scalar(0,255,0);
                break;
            case 1:
                color = cv::Scalar(0,255,0);
                break;
            case 2:
                color = cv::Scalar(0,0,255);
                break;
            case 3:
                color = cv::Scalar(0,255,255);
                break;
            }
            //cv::put
            cv::rectangle(frame1,cv::Point(box.x,box.y),cv::Point(box.x+box.w,box.y+box.h),color,1);
            std::string prob_str = "prob:"+ std::to_string(box.prob);
            cv::putText(frame1,prob_str,cv::Point(box.x,box.y-10),cv::FONT_HERSHEY_SIMPLEX,1.0,color);
        }
        std::cout << "result size" << result.size()<< std::endl;
        cv::imshow("result",frame1);
        std::string saveFileName = "./result/result_"+std::to_string(j)+".jpg" ;
        cv::imwrite(saveFileName,frame1);
        cv::waitKey(1000);


    }

    return 0;
}
